package com.kgc.dao.mapper.user;

import com.kgc.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;

/**
 * @author hyj
 * @time 2024/4/2 15:58
 * @describe
 */

public interface OwnerMapper {
    /**
     * 查询个人信息
     *
     * @param id id
     * @return User
     */
    @Select("select user_id, username, email, image, created_at, status, integral from users where user_id=#{id}")
    User getOwner(Integer id);

    /**
     * 判断该用户名是否已注册
     *
     * @param username 用户名
     * @return null:not_exist User:exist
     */
    @Select("select * from users where username=#{username}")
    User selectByUsername(String username);

    /**
     * 判断该邮箱是否已注册
     *
     * @param email 邮箱
     * @return null:not_exist User:exist
     */
    @Select("select * from users where email=#{email}")
    User selectByEmail(String email);

    /**
     * 更新个人信息
     *
     * @param id       id
     * @param username 用户名
     * @param email    邮箱
     * @return 1:成功 0:失败
     */
    @UpdateProvider(type = SqlProvide.class, method = "updateOwner")
    int updateOwner(@Param("id") Integer id, @Param("username") String username, @Param("email") String email);
}
